<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>求阶乘的值</title>
    <script>
        //求阶乘 (n! = 1 * 2 * 3 ..... * (n-1) * n)
        var func = function factorial(num){
            var result = 1;
            for(var i = 2 ; i <= num ;i++){
                result = result * i;
            }
            return result;
        }
        console.log(func(4));

        var func2 = function factorial2(num){
            if(num <= 1){
                return 1;
            }else{
                return  (num * factorial2(num-1));
            }
        }
        console.log(func2(4));

        aa();   //此时在函数前面调用可以
        function aa(){

        }


        aa();   //报错
        console.log(typeof  aa);   //undefined
        var aa = function(){

        }

        //匿名函数
        $("div").click(function(){

        })
    </script>
</head>
<body>

</body>
</html>